<?php


namespace app\admin\model;


use app\admin\model\Staff;
use think\facade\Env;
use think\facade\Log;
use think\Model;


class AllocRule extends Model
{
    protected $autoWriteTimestamp = true;

    /**
     * @param $data
     * @param $serverType
     * @return string
     * 规则保存
     */
    public static function allocSave($data,$serverType)
    {
        $data["server_type"] = $serverType;
        $ru = AllocRule::where("server_type",$serverType)->find();
        if($ru){
            AllocRule::where("id",$ru["id"])->data($data)->update();
        }else{
            AllocRule::create($data);
        }

        return "";
    }

    /**
     * @param $id
     * @param $serverType
     * @return AllocRule
     * 规格详情
     */
    public static function allocDet($serverType)
    {
        $rule = AllocRule::where("server_type",$serverType)->find();

        return $rule;
    }

    /**
     * @param $user_no
     * @param $url
     * @param $serverType
     * @return mixed|
     * 规则
     */
    public static function allocRule($user_no,$url,$serverType):string
    {
        $rule = AllocRule::where("server_type",$serverType)->find();
        if(!$rule){
            Log::info("规则未设置~");
        }
        // 指定客服
        if($rule["rule_type"] == 3){
            if(!$rule["staff_no"]) {
                Log::info("客服不存在~");
                return "PXS000003";
            }
            return $rule["staff_no"];
        }else{
            $dutyIdArr = Duty::getServerData($serverType);
            return staff::getStaffList($dutyIdArr,$serverType);
        }
    }
}